﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.IO;
using System.Linq;
using System.Text;
using ReflectionStudio.Core;
using ReflectionStudio.Core.Events;
using IntexReport.DataSource;
namespace WPFExcelReport
{

    public class FLTRMATMOVData : BaseFunction
    {
        public bool flagstartmtr;
        public bool flagRegenerateLastMonthData;
        string InvDate;
        string LASTINVDATE;
        ArrayList ListGBInventory;
        ArrayList ListTris = new ArrayList();
        string fileGBDATINV = Path.Combine(PathHelper.ApplicationPath, @"Report\Financial\GBDATINV.xml");
        SetData setINV = new SetData();
        DataTable tbGBDATINV;
        List<GBMOVEMENT> ListMov;
        List<WGSummary> ListWGSummary;
        string TrisInclude = "";
        public int ThreadCount;
        private string OrderNum;
        DataTable tbMov;
        public FLTRMATMOVData()
            : base()
        {
           
        }
        public FLTRMATMOVData(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
        }
        public FLTRMATMOVData(OracleConnection _myConnection, IntexReptServBLClient _proxy, string userID = "        ")
            : base(_myConnection, _proxy, userID)
        {
        }
        public void GetStartInv(DataRow dwProperty)
        {
            DataSet setResult = new DataSet();
            DataTable tableLocal = null;
            string LO = "FI", LB = "PR", ABTYPE = "'ES','D7'";
            string STARTDATE, ENDDATE, INVDATE = "";
            STARTDATE = dwProperty["STARTDATE"].ToString().Trim();
            ENDDATE = dwProperty["ENDDATE"].ToString().Trim();
            INVDATE = GetDateAddDays(STARTDATE, 0);
            try
            {
                SetData setTemp = new SetData();
                
                OracleCommand or1 = OracleDB.CreateCommand();
                or1.CommandText = "SELECT A.ICCGLMANDANT AS GMMANDANT,to_char(sysdate,'yyyy') AS GMJJJJ, "
                    + " to_char(sysdate,'mm') AS GMMM,to_char(sysdate,'dd') AS GMTT,DECODE(A.ICCGLLO,'01','FI',A.ICCGLLO) AS GMLO, "
                    + " MAX(A.ICCGLLB) AS GMLB,B.GPGART AS GMGART,B.GPGVAR AS GMGVAR,C.GSGARNBEZ AS GMGDES, "
                    + " B.GPGFARBE AS GMGCOLOR,D.GSCBEZ AS GMGCDES,A.ICCGLPARTIE AS GMPARTIE,A.ICCGLPARTIE AS GMBATCH, "
                    + " '' AS GMSPPART,'' AS GMFBPART,'' AS GMZWART,SUM(A.ICCGLBSTKG/1000) AS GMSTARTQTY, "
                    + " 0 AS GMPOIN,0 AS GMMUIN,0 AS GMPDIN,0 AS GMSPIN ,0 AS GMD7IN,0 AS GMESIN,0 AS GMRDOUT, "
                    + " 0 AS GMCLOUT,0 AS GMRSOUT,0 AS GMADJIN,0 AS GMREIN ,0 AS GMORIN ,0 AS GMSTOUT, "
                    + " 0 AS GMTOOUT,0 AS GMCSOUT,0 AS GMCRIN ,0 AS GMOSOUT,0 AS GMPDOUT,0 AS GMSPOUT, "
                    + " 0 AS GMOCOUT,0 AS GMOSIN ,0 AS GMOROUT,0 AS GMENDQTY,0 AS GMELSEIN,0 AS GMELSEOUT, "
                    + " 0 AS GMSTARTDAT ,' ' AS GMREMARK  "
                    + "   FROM ICC_GLLG A,GPDAT B,GSDAT C,GSCOLOR D   "
                    + "  WHERE A.ICCGLMANDANT = B.GPMANDANT AND A.ICCGLPARTIE = B.GPPARTIE "
                    + "  AND A.ICCGLPARTIEKZ = B.GPPARTIEKZ AND B.GPMANDANT = C.GSMANDANT(+) "
                    + "  AND B.GPGART = C.GSART(+) AND B.GPGVAR = C.GSVAR(+) "
                    + "  AND B.GPMANDANT = D.GSCMANDANT(+) AND B.GPGART = D.GSCART(+) "
                    + "  AND B.GPGVAR = D.GSCVAR(+) AND B.GPGFARBE = D.GSCFARBE(+) "
                    + "  AND A.ICCGLDAT = '" + INVDATE + "'  AND A.ICCGLLO in ('FI','01')  "
                    + "  AND B.GPGART LIKE '1%'  "
                    + "  AND A.ICCGLLB IN ('1P','2P','3P','OP','KO','CC','RD') "
                    + "  GROUP BY A.ICCGLMANDANT,to_char(sysdate,'yyyy'), "
                    + " to_char(sysdate,'mm'),to_char(sysdate,'dd'),DECODE(A.ICCGLLO,'01','FI',A.ICCGLLO), "
                    + " B.GPGART,B.GPGVAR,C.GSGARNBEZ,B.GPGFARBE,D.GSCBEZ,A.ICCGLPARTIE "
                    + " ORDER BY 5, 6, 7,8,10,12";
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    tableLocal = setResult.Tables[0];
                    tableLocal.TableName = "CN_GMBALANCE";
                }
                setTemp.Merge(setResult);
                DataRow dwInv = null;
                byte[] b;
                string value;
                string ColumnName = "";
                foreach (DataRow dwTemp in setTemp.CN_GMBALANCE.Rows)
                {
                    ColumnName = "GMGDES";
                    b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[ColumnName].ToString().Trim());
                    value = Encoding.GetEncoding("gb2312").GetString(b);
                    dwTemp[ColumnName] = value;
                    ColumnName = "GMGCDES";
                    b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[ColumnName].ToString().Trim());
                    value = Encoding.GetEncoding("gb2312").GetString(b);
                    dwTemp[ColumnName] = value;
                    //如果在期末中没有，则期末为0；
                    //如果在期末中已经有，则更新期初数量为
                    /*
                     query = from dwX in setINV.CN_GMBALANCE.AsEnumerable()
                                where dwX["GMGART"].ToString() == dwTemp["GMGART"].ToString()
                                & dwX["GMGVAR"].ToString() == dwTemp["GMGVAR"].ToString()
                                & dwX["GMGCOLOR"].ToString() == dwTemp["GMGCOLOR"].ToString()
                                select dwX;
                     */
                    dwInv = null;
                    //查询期末
                    var query = from dwX in setINV.CN_GMBALANCE.AsEnumerable()
                            where 
                            dwX["GMPARTIE"].ToString() == dwTemp["GMPARTIE"].ToString()
                            &&
                            dwX["GMLO"].ToString() == dwTemp["GMLO"].ToString()
                            select dwX;
                    foreach (DataRow dwX in query)
                    {
                        dwInv = dwX;
                    }
                    if (dwInv == null)
                    {
                        //如果在期末中没有，则期末为0；
                        dwInv = setINV.CN_GMBALANCE.NewCN_GMBALANCERow();
                        dwInv.ItemArray = dwTemp.ItemArray;
                        dwInv["GMENDQTY"] = 0;
                        setINV.CN_GMBALANCE.Rows.Add(dwInv);
                        continue;
                    }
                    dwInv["GMSTARTQTY"] = dwTemp["GMSTARTQTY"];
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public void GetEndInv(DataRow dwProperty)
        {
            //整理一个库存表，包括所有涉及到的纱批信息，可能从GABEW获取的纱批 
            DataSet setResult = new DataSet();
            DataTable tableLocal = null;
            string LO = "FI", LB = "PR";
            string STARTDATE, ENDDATE, INVDATE = "";
            STARTDATE = dwProperty["STARTDATE"].ToString().Trim();
            ENDDATE = dwProperty["ENDDATE"].ToString().Trim();
            INVDATE = GetDateAddDays(ENDDATE, 0);
            try
            {
                //GMMANDANT GMJJJJ GMMM GMTT GMLO GMLB GMGART     GMGVAR GMGCOLOR   GMGDES   
                //GMPARTIE   GMBATCH    GMSTARTQTY GMEKIN    GMELSEIN  GMABOUT   GSYJOUT   GSEXPROUT
                // GMEXDYEOUT GMDEVOUT  GMEKOUT   GMENDQTY  GMEXPOUT  GMEXPIN   GMABYARN 
                // GMYJYARN  GMDYEDYARN GMENDDAT  GMSTARTDAT  
                OracleCommand or1 = OracleDB.CreateCommand();
                or1.CommandText = "SELECT A.ICCGLMANDANT AS GMMANDANT,to_char(sysdate,'yyyy') AS GMJJJJ, "
                    + " to_char(sysdate,'mm') AS GMMM,to_char(sysdate,'dd') AS GMTT,DECODE(A.ICCGLLO,'01','FI',A.ICCGLLO) AS GMLO, "
                    + " MAX(A.ICCGLLB) AS GMLB,B.GPGART AS GMGART,B.GPGVAR AS GMGVAR,C.GSGARNBEZ AS GMGDES, "
                    + " B.GPGFARBE AS GMGCOLOR,D.GSCBEZ AS GMGCDES,A.ICCGLPARTIE AS GMPARTIE,A.ICCGLPARTIE AS GMBATCH, "
                    + " '' AS GMSPPART,'' AS GMFBPART,'' AS GMZWART,0 AS GMSTARTQTY, "
                    + " 0 AS GMPOIN,0 AS GMMUIN,0 AS GMPDIN,0 AS GMSPIN ,0 AS GMD7IN,0 AS GMESIN,0 AS GMRDOUT, "
                    + " 0 AS GMCLOUT,0 AS GMRSOUT,0 AS GMADJIN,0 AS GMREIN ,0 AS GMORIN ,0 AS GMSTOUT, "
                    + " 0 AS GMTOOUT,0 AS GMCSOUT,0 AS GMCRIN ,0 AS GMOSOUT,0 AS GMPDOUT,0 AS GMSPOUT, "
                    + " 0 AS GMOCOUT,0 AS GMOSIN ,0 AS GMOROUT,SUM(A.ICCGLBSTKG/1000) AS GMENDQTY, "
                    + " 0 AS GMELSEIN,0 AS GMELSEOUT,0 AS GMSTARTDAT ,' ' AS GMREMARK  "
                    + "   FROM ICC_GLLG A,GPDAT B,GSDAT C,GSCOLOR D   "
                    + "  WHERE A.ICCGLMANDANT = B.GPMANDANT AND A.ICCGLPARTIE = B.GPPARTIE "
                    + "  AND A.ICCGLPARTIEKZ = B.GPPARTIEKZ AND B.GPMANDANT = C.GSMANDANT(+) "
                    + "  AND B.GPGART = C.GSART(+) AND B.GPGVAR = C.GSVAR(+) "
                    + "  AND B.GPMANDANT = D.GSCMANDANT(+) AND B.GPGART = D.GSCART(+) "
                    + "  AND B.GPGVAR = D.GSCVAR(+) AND B.GPGFARBE = D.GSCFARBE(+) "
                    + "  AND A.ICCGLDAT = '" + INVDATE + "'  AND A.ICCGLLO in ('FI','01')  "
                    + "  AND B.GPGART LIKE '1%'  "
                    + "  AND A.ICCGLLB IN ('1P','2P','3P','OP','KO','CC','RD') "
                    + "  GROUP BY A.ICCGLMANDANT,to_char(sysdate,'yyyy'), "
                    + " to_char(sysdate,'mm'),to_char(sysdate,'dd'),DECODE(A.ICCGLLO,'01','FI',A.ICCGLLO), "
                    + " B.GPGART,B.GPGVAR,C.GSGARNBEZ,B.GPGFARBE,D.GSCBEZ,A.ICCGLPARTIE "
                    + " ORDER BY 5, 6, 7,8,10,12";
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                { 
                    tableLocal = setResult.Tables[0];
                    tableLocal.TableName = "CN_GMBALANCE";
                }
                //setINV.Merge(setResult); 
                DataRow dwNew = null;
                byte[] b;
                string value;
                string ColumnName = "";
                foreach (DataRow dwTemp in tableLocal.Rows)
                {
                    ColumnName = "GMGDES";
                    b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[ColumnName].ToString().Trim());
                    value = Encoding.GetEncoding("gb2312").GetString(b);
                    dwTemp[ColumnName] = value;
                    ColumnName = "GMGCDES";
                    b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[ColumnName].ToString().Trim());
                    value = Encoding.GetEncoding("gb2312").GetString(b);
                    dwTemp[ColumnName] = value;
                    dwNew = setINV.CN_GMBALANCE.NewCN_GMBALANCERow();
                    dwNew.ItemArray = dwTemp.ItemArray;
                    setINV.CN_GMBALANCE.Rows.Add(dwNew);
                } 
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public void GetMovement(DataRow dwProperty)
        {
            DataSet setResult = new DataSet();
            DataTable tableLocal = null;
            string STARTDATE, ENDDATE;
            STARTDATE = dwProperty["STARTDATE"].ToString().Trim();
            ENDDATE = dwProperty["ENDDATE"].ToString().Trim();
            try
            {
               // SELECT GABPARTIE,GABFC,GABBS,GABAUFTYP,GABLB,GABAUFKRS,SUM(GABKG) AS GABKG FROM GABEW
// GROUP BY GABPARTIE,GABFC,GABBS,GABAUFTYP,GABLB,GABAUFKRS
                OracleCommand or1 = OracleDB.CreateCommand();
                #region===============ICC_WBMOV=======================
                /*"SELECT GABLO,GABPARTIE,GABFC,GABBS,GABAUFTYP,GABLB,GABAUFKRS,SUM(GABKG) AS GABKG FROM GABEW "
                    +" WHERE "
                    + " GABBUCHDAT>='"+STARTDATE+"' AND GABBUCHDAT<'"+ENDDATE+"' AND "
                    + " ((GABAUFTYP = 'K' AND GABBS='21' AND GABAUFKRS = '00' AND GABFC ='VV20' AND GABLO<>'FI' )"
                    +" OR "
                    + " (GABFC ='GB11' AND GABBS = '42' AND GABLO<>'FI' )"
                    +" OR"
                    +" ((GABAUFKRS ='ES' OR GABAUFKRS = 'D7') AND GABBS = '38'))"
                    + " GROUP BY GABLO,GABPARTIE,GABFC,GABBS,GABAUFTYP,GABLB,GABAUFKRS"*/
                or1.CommandText = "SELECT DECODE(A.ICCWH,'01','FI',A.ICCWH) AS ICCWH,A.ICCGABTYPE,A.ICCGABPARTIE,A.ICCGABART,A.ICCGABVAR,A.ICCGSGARNBEZ, "
                    + " A.ICCGABFARBE,A.ICCGSCBEZ,A.ICCGABLB,SUM(ICCGABKG) AS ICCGABKG  "
                    + " FROM ICC_GABEW A " 
                    + " WHERE A.ICCGABBUCHDAT>='"+STARTDATE+"' AND A.ICCGABBUCHDAT<'"+ENDDATE+"' "
                    + " AND  A.ICCGABTYPE IN ('POI','MUI','PDI','SPI','D7I','ESI','RDO','CLO','RSO','ADJ','REI','ORI','STO','TOO','CSO','CRI','OSO','PDO','SPO') "
                    + " AND A.ICCWH in ('FI','01')  AND A.ICCGABART LIKE '1%' "
                    + " GROUP BY DECODE(A.ICCWH,'01','FI',A.ICCWH),A.ICCGABTYPE,A.ICCGABPARTIE,A.ICCGABART,A.ICCGABVAR,A.ICCGSGARNBEZ,A.ICCGABFARBE,A.ICCGSCBEZ,A.ICCGABLB "
                     ;
                #endregion
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    tableLocal = setResult.Tables[0];
                    tableLocal.TableName = "GABEW";
                    byte[] b;
                    string value;
                    string ColumnName = "";
                    foreach (DataRow dwTemp in tableLocal.Rows)
                    {
                        ColumnName = "ICCGSGARNBEZ";
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[ColumnName].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dwTemp[ColumnName] = value;
                        ColumnName = "ICCGSCBEZ";
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[ColumnName].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dwTemp[ColumnName] = value;
                        EventDispatcher.Instance.RaiseStatus("计算结存", StatusEventType.RunningProgress);
                        //用Linq实现所有跟该批号相关的移动累计
                        BalanceQty(dwTemp);
                    }
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        private void BalanceQty(DataRow dwGABEW)
        {
            bool isNew = false;
            DataRow dwInv = null;
            try
            {
                OracleCommand or1 = OracleDB.CreateCommand(); 
                string intexlot = dwGABEW["ICCGABPARTIE"].ToString();
                string LO = dwGABEW["ICCWH"].ToString();
                string GMGART = dwGABEW["ICCGABART"].ToString();
                string GMGVAR = dwGABEW["ICCGABVAR"].ToString();
                string GMGDES = dwGABEW["ICCGSGARNBEZ"].ToString();
                string GMGCOLOR = dwGABEW["ICCGABFARBE"].ToString();
                string GMGCDES = dwGABEW["ICCGSCBEZ"].ToString();
                /*if (intexlot.Contains( "37013"))
                {
                    isNew = false;
                }*/
                #region=========是否总表中需要增加新纪录===============
                var query = from dwX in setINV.CN_GMBALANCE.AsEnumerable()
                            where dwX["GMPARTIE"].ToString().Trim() == intexlot.Trim()
                            && dwX["GMLO"].ToString().Trim() == LO
                            select dwX;
                foreach (DataRow dwX in query)
                {
                    dwInv = dwX;
                }
                if (dwInv == null)
                {
                    //如果在期末中没有，则期末为0；
                    isNew = true;
                    dwInv = setINV.CN_GMBALANCE.NewCN_GMBALANCERow();
                    //dwInv.ItemArray = setINV.CN_GMBALANCE.Rows[0].ItemArray;
                    /*GMMANDANT,GMJJJJ ,GMMM ,GMTT ,GMLO ,GMLB ,GMGART ,GMGVAR ,GMGDES ,GMGCOLOR ,GMGCDES,
GMPARTIE ,GMBATCH,GMSPPART ,GMFBPART ,GMZWART,GMSTARTQTY ,GMPOIN ,GMMUIN ,GMPDIN ,GMSPIN ,
GMD7IN ,GMESIN ,GMRDOUT,GMCLOUT,GMRSOUT,GMADJIN,GMREIN ,GMORIN ,GMSTOUT,GMTOOUT,GMCSOUT,
GMCRIN ,GMOSOUT,GMPDOUT,GMSPOUT,GMOCOUT,GMOSIN ,GMOROUT,GMSTARTDAT ,GMREMARK*/
                            dwInv["GMLO"] = LO;
                            dwInv["GMGDES"] = GMGDES;
                            dwInv["GMGART"] = GMGART;
                            dwInv["GMGVAR"] = GMGVAR;
                            dwInv["GMGCOLOR"] = GMGCOLOR;
                            dwInv["GMGCDES"] = GMGCDES;
                            dwInv["GMPARTIE"] = intexlot;
                            dwInv["GMSTARTQTY"] = 0.0;
                            dwInv["GMPOIN"] = 0.0;
                            dwInv["GMMUIN"] = 0.0;
                            dwInv["GMPDIN"] = 0.0;
                            dwInv["GMSPIN"] = 0.0;
                            dwInv["GMD7IN"] = 0.0;
                            dwInv["GMESIN"] = 0.0;
                            dwInv["GMRDOUT"] = 0.0;
                            dwInv["GMCLOUT"] = 0.0;
                            dwInv["GMRSOUT"] = 0.0;
                            dwInv["GMADJIN"] = 0.0;
                            dwInv["GMREIN"] = 0.0;
                            dwInv["GMORIN"] = 0.0;
                            dwInv["GMSTOUT"] = 0.0;
                            dwInv["GMTOOUT"] = 0.0;
                            dwInv["GMCSOUT"] = 0.0;
                            dwInv["GMCRIN"] = 0.0;
                            dwInv["GMOSOUT"] = 0.0;
                            dwInv["GMPDOUT"] = 0.0;
                            dwInv["GMSPOUT"] = 0.0;
                            dwInv["GMOCOUT"] = 0.0;
                            dwInv["GMOSIN"] = 0.0;
                            dwInv["GMOROUT"] = 0.0;
                            dwInv["GMENDQTY"] = 0.0;
                            dwInv["GMELSEIN"] = 0.0;
                            dwInv["GMELSEOUT"] = 0.0;
                            dwInv["GMSTARTDAT"] = 0.0;
                     
                }
                #endregion
                //GABPARTIE	GABLO	GABLB	GABLP	GABAUFTYP	GABAUFKRS	GABAUFLFD	GABAUFPOS	GABBS	GABFC
                //string GABPARTIE = dwGABEW["ICCGABPARTIE"].ToString().Trim();
                //string GABLO = dwGABEW["ICCWH"].ToString().Trim();
                string GABLB = dwGABEW["ICCGABLB"].ToString().Trim();
                //string GABAUFTYP = dwGABEW["ICCGABAUFTYP"].ToString().Trim();
                //string GABAUFKRS = dwGABEW["ICCGABAUFKRS"].ToString().Trim();
                //string GABBS = dwGABEW["ICCGABBS"].ToString().Trim();
                //string GABFC = dwGABEW["ICCGABFC"].ToString().Trim();
                string ICCGABTYPE = dwGABEW["ICCGABTYPE"].ToString().Trim();
                decimal GABKG =  System.Convert.ToDecimal(dwGABEW["ICCGABKG"].ToString())/1000;
                #region=========================================
                decimal value = 0;
                /*'POI','MUI','PDI','SPI','D7I','ESI','RDO','CLO','RSO','ADJ','REI',
                 * 'ORI','STO','TOO','CSO','CRI','OSO','PDO','SPO' */
                #region================采购入库========================
                if (ICCGABTYPE == "POI")
                {
                    value = System.Convert.ToDecimal(dwInv["GMPOIN"].ToString());
                    dwInv["GMPOIN"] = value + GABKG;
                }
                #endregion
                #region================手工入库========================
                if (ICCGABTYPE == "MUI")
                    {
                        value = System.Convert.ToDecimal(dwInv["GMMUIN"].ToString());
                        dwInv["GMMUIN"] = value + GABKG;
                    }
                #endregion
                #region================摇绞入库========================
                if (ICCGABTYPE == "PDI")
                {
                    value = System.Convert.ToDecimal(dwInv["GMPDIN"].ToString());
                    dwInv["GMPDIN"] = value + GABKG;
                }
                #endregion
                #region================生产入库========================
                if (ICCGABTYPE == "SPI")
                {
                    
                        value = System.Convert.ToDecimal(dwInv["GMSPIN"].ToString());
                        dwInv["GMSPIN"] = value + GABKG;
                    
                }
                #endregion
                #region================染色入库========================
                if (ICCGABTYPE == "D7I")
                {

                    value = System.Convert.ToDecimal(dwInv["GMD7IN"].ToString());
                    dwInv["GMD7IN"] = value + GABKG;

                }
                #endregion
                #region================外加工入库========================
                if (ICCGABTYPE == "ESI")
                {

                    value = System.Convert.ToDecimal(dwInv["GMESIN"].ToString());
                    dwInv["GMESIN"] = value + GABKG;

                }
                #endregion
                #region================研发消耗========================
                if (ICCGABTYPE == "RDO")
                {

                    value = System.Convert.ToDecimal(dwInv["GMRDOUT"].ToString());
                    dwInv["GMRDOUT"] = value + GABKG;

                }
                #endregion
                #region================色卡消耗========================
                if (ICCGABTYPE == "CLO")
                {

                    value = System.Convert.ToDecimal(dwInv["GMCLOUT"].ToString());
                    dwInv["GMCLOUT"] = value + GABKG;

                }
                #endregion
                #region================采购退货========================
                if (ICCGABTYPE == "RSO")
                {

                    value = System.Convert.ToDecimal(dwInv["GMRSOUT"].ToString());
                    dwInv["GMRSOUT"] = value + GABKG;

                }
                #endregion
                #region================调整========================
                if (ICCGABTYPE == "ADJ")
                {
                    if (GABLB != "PR")
                    {

                        value = System.Convert.ToDecimal(dwInv["GMADJIN"].ToString());
                        dwInv["GMADJIN"] = value + GABKG;
                    }

                }
                #endregion
                #region================生产退货========================
                if (ICCGABTYPE == "REI")
                {

                    value = System.Convert.ToDecimal(dwInv["GMREIN"].ToString());
                    dwInv["GMREIN"] = value + GABKG;

                }
                #endregion
                #region================外加工厂退货========================
                if (ICCGABTYPE == "ORI")
                {

                    value = System.Convert.ToDecimal(dwInv["GMORIN"].ToString());
                    dwInv["GMORIN"] = value + GABKG;

                }
                #endregion
                #region================转生产车间========================
                if (ICCGABTYPE == "STO")
                {

                    value = System.Convert.ToDecimal(dwInv["GMSTOUT"].ToString());
                    dwInv["GMSTOUT"] = value + GABKG;

                }
                #endregion
                #region================转外加工厂========================
                if (ICCGABTYPE == "TOO")
                {

                    value = System.Convert.ToDecimal(dwInv["GMTOOUT"].ToString());
                    dwInv["GMTOOUT"] = value + GABKG;

                }
                #endregion
                #region================销售出货========================
                if (ICCGABTYPE == "CSO")
                {

                    value = System.Convert.ToDecimal(dwInv["GMCSOUT"].ToString());
                    dwInv["GMCSOUT"] = value + GABKG;

                }
                #endregion
                #region================销售退货========================
                if (ICCGABTYPE == "CRI")
                {

                    value = System.Convert.ToDecimal(dwInv["GMCRIN"].ToString());
                    dwInv["GMCRIN"] = value + GABKG;

                }
                #endregion
                #region================委外发纱========================
                if (ICCGABTYPE == "OSO")
                {

                    value = System.Convert.ToDecimal(dwInv["GMOSOUT"].ToString());
                    dwInv["GMOSOUT"] = value + GABKG;

                }
                #endregion
                #region================摇绞领料========================
                if (ICCGABTYPE == "PDO")
                {

                    value = System.Convert.ToDecimal(dwInv["GMPDOUT"].ToString());
                    dwInv["GMPDOUT"] = value + GABKG;

                }
                #endregion
                #region================生产领料========================
                if (ICCGABTYPE == "SPO")
                {

                    value = System.Convert.ToDecimal(dwInv["GMSPOUT"].ToString());
                    dwInv["GMSPOUT"] = value + GABKG;

                }
                #endregion
                #endregion
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            finally
            {
                if (isNew)
                {
                    setINV.CN_GMBALANCE.Rows.Add(dwInv);
                }
            }
        }
        public DataSet GetData(DataRow dwUI)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            try
            {
                EventDispatcher.Instance.RaiseStatus("查询开始", StatusEventType.StartProgress);
                setINV.Clear();
                EventDispatcher.Instance.RaiseStatus("装载期末结存表", StatusEventType.RunningProgress);
                GetEndInv(dwUI);
                EventDispatcher.Instance.RaiseStatus("装载期初结存表", StatusEventType.RunningProgress);
                GetStartInv(dwUI);
                EventDispatcher.Instance.RaiseStatus("装载出入库记录", StatusEventType.RunningProgress);
                GetMovement(dwUI);
                EventDispatcher.Instance.RaiseStatus("计算结存", StatusEventType.RunningProgress);
                setReturn.Merge(setResult);
                EventDispatcher.Instance.RaiseStatus("保存结存表", StatusEventType.RunningProgress);
                EventDispatcher.Instance.RaiseStatus("查询完成", StatusEventType.StopProgress);
            }
            catch (Exception ex)
            {
                Tracer.Error(ABPOS + ex.StackTrace, ex);
            }
            return setINV;
        }
    }
}